<?php
if(!defined('IN_DISCUZ')) {
	exit('Access Denied');
}

if(!$_G['uid']) {
	showmessage('not_loggedin', NULL, array(), array('login' => 1));
}

require_once './source/function/function_core.php';
require_once './source/function/function_home.php';

$result = DB::fetch_first("SELECT * FROM ".DB::table('common_setting')." WHERE skey = 'profilegroup' ");
$defaultop = '';
if(!empty($result['svalue'])) {
	$profilegroup = unserialize($result['svalue']);
	foreach($profilegroup as $key => $value) {
		if($value['available']) {
			$defaultop = $key;
			break;
		}
	}
}

$operation = 'plugin';
$actives = array('profile' =>' class="a"');
$showbtn = 0;

if ($_G['gp_profilesubmit']) {
	$name =  $_G['gp_name'];
	$father_name =  getgpc('father_name');
	$mother_name =  getgpc('mother_name');
	$nick_name =  $_G['gp_nick_name'];
	$birthyear = $_G['gp_birthyear'];
	$birthmonth = $_G['gp_birthmonth'];
	$birthday = $_G['gp_birthday'];
	$gender = $_G['gp_gender'];
	$prepare_pregnancy = $_G['gp_prepare_pregnancy'];
	$yuer_weekly = $_G['gp_yuer_weekly'];
	$yuer_receive_freq = $_G['gp_yuer_receive_freq'];

	$data = array('name' => $name, 'nick_name' => $nick_name, 'father_name' => $father_name, 'mother_name' => $mother_name,
		'birthyear' => $birthyear, 'birthmonth' => $birthmonth, 'birthday' => $birthday,
		'gender' => $gender, 'prepare_pregnancy' => $prepare_pregnancy, 'yuer_weekly' => $yuer_weekly, 'yuer_receive_freq' => $yuer_receive_freq,
		'update_time' => time() );

	$update_count = DB::update('common_member_profile_baby', $data, ' uid = '.$_G['uid'] );
	if ($update_count == 0) {
		$data['uid'] = $_G['uid'];
		$data['insert_time'] = $data['update_time'];
		DB::insert('common_member_profile_baby', $data);
	}
	$message='保存宝宝信息成功。';

	showmessage($message, '', array(), array('alert' => 'right') );
}
else{
	$user_info = getspace($_G['uid']);
	$email = $user_info['email'];
	$query = DB::query(" SELECT * FROM ".DB::table('common_member_profile_baby')." WHERE uid= ".$_G['uid']);
	$result = DB::fetch($query);
	if(!empty($result['uid'])) {
		$name =  $result['name'];
		$nick_name =  $result['nick_name'];
		$father_name =  $result['father_name'];
		$mother_name =  $result['mother_name'];
		$birthyear = $result['birthyear'];
		$birthmonth = $result['birthmonth'];
		$birthday = $result['birthday'];
		$gender = $result['gender'];
		$prepare_pregnancy = $result['prepare_pregnancy'];
		$yuer_weekly = $result['yuer_weekly'];
		$yuer_receive_freq = $result['yuer_receive_freq'];
	}
}

$years = array();
$nowy = dgmdate($_G['timestamp'], 'Y');
for ($i= -2; $i < 12; $i++) {
	$they = $nowy - $i;
	$years[] = $they;
}

$months = array();
for ($i= 1; $i < 13; $i++) {
	$months[] = $i;
}

$days = array();
for ($i= 1; $i < 32; $i++) {
	$days[] = $i;
}

include template("home/spacecp_profile");

?>